package control;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.PriorityDTO;
import business.PriorityManager;

public class PriorityServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public PriorityServlet()
	{
		super();
	}
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}  	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	} 
	
	/**
	 * @param request
	 * @param response
	 * @throws IOException 
	 * @throws ServletException 
	 */
	private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		PriorityManager pm = new PriorityManager();
		
		ArrayList<PriorityDTO> data = new ArrayList<PriorityDTO>();
		data = pm.findAllPriorities();
				String checkpriority= request.getParameter("checkpriority");
				RequestDispatcher rd;
			request.setAttribute("priorities", data);
			
			if(checkpriority.equals("true"))
			{
			rd = request.getRequestDispatcher("Make_Booking.jsp");
			}
			else
			{
			rd = request.getRequestDispatcher("/BookingDetails");
			}
			try {
				rd.forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
}
